package org.sqlproc.engine.impl.type.hibernate;

import org.hibernate.SQLQuery;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LongType;
import org.hibernate.type.Type;

public class TypeUtils {

    static SqlIntegerType integerType = new SqlIntegerType();
    static SqlLongType longType = new SqlLongType();

    public static void addScalar(SQLQuery query, String name, Type hibernateType) {
        if (hibernateType == null) {
            query.addScalar(name);
            return;
        }

        Class<?> clazz = hibernateType.getClass();
        if (clazz == IntegerType.class) {
            query.addScalar(name, integerType);
        } else if (clazz == LongType.class) {
            query.addScalar(name, longType);
        } else {
            query.addScalar(name, hibernateType);
        }
    }
}
